﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TBM.Core
{
    public class ParamType
    {
        /// <summary>
        /// 整型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int? Int(object value)
        {
            int _value;

            if (value != null && int.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 长整型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static long? Long(object value)
        {
            long _value;

            if (value != null && long.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 单精度型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static float? Float(object value)
        {
            float _value;

            if (value != null && float.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 双精度型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double? Double(object value)
        {
            double _value;

            if (value != null && double.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 数值型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static decimal? Decimal(object value)
        {
            decimal _value;

            if (value != null && decimal.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 布尔型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool? Boolean(object value)
        {
            bool _value;

            if (value != null && bool.TryParse(value.ToString(), out _value))
            {
                return _value;
            }
            else
            {
                return null;
            }
        }
    }
}
